//
//  ViewController.swift
//  5swiftHere
//
//  Created by 杜承玖 on 2/11/15.
//  Copyright (c) 2015 redianying. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    
    var color = UIColor.whiteColor() //需要切换的颜色
    
    //是否关闭状态, 相当于是否颜色为黑色
    var offState : Bool = false {
        willSet(newValue) {
            if newValue { //判断状态为 true
                self.view.backgroundColor = color //背景颜色
            } else {
                self.view.backgroundColor = UIColor.blackColor()
            }
        }
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.view.backgroundColor = color
        
        offState = false
        
        NSTimer.scheduledTimerWithTimeInterval(0.19, target: self, selector: "updateState", userInfo: nil, repeats: true)
        
        // Do any additional setup after loading the view, typically from a nib.
    }
    
    @IBAction func handleBack(sender: UIButton) {
        self.navigationController?.popViewControllerAnimated(true)
    }
    
    func updateState() {
        println("1")
        
        /*
        if offState {
            offState = false
        } else {
            offState = true
        }
        */
        
        offState = !offState
        
    }
    
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

